package com.cas.authentication.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.jasig.services.persondir.IPersonAttributes;
import org.jasig.services.persondir.support.AttributeNamedPersonImpl;
import org.jasig.services.persondir.support.StubPersonAttributeDao;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

public class MyStubPersonAttributeDao extends StubPersonAttributeDao {
	
	private String sql;
	private DataSource ds;
	private SimpleJdbcTemplate simpleJdbcTemplate;
	
	public MyStubPersonAttributeDao(DataSource ds,String sql){
		this.sql = sql;
		simpleJdbcTemplate = new SimpleJdbcTemplate(ds);
	}
	
	@Override
	public IPersonAttributes getPerson(String uid) {
		List<Map<String,Object>> list = simpleJdbcTemplate.queryForList(sql, uid);
		
		Map<String,List<Object>> map = new HashMap<String,List<Object>>() ;
//		map.put(uid, list.get(0));
		return new AttributeNamedPersonImpl(map);
	}

}
